package Information_sysyem_jdbc.Test;

import Information_sysyem_jdbc.Service.InformationService;
import Information_sysyem_jdbc.Service.impl.InformationServiceimpl;
import Information_sysyem_jdbc.entity.Information;

import java.util.List;
import java.util.Scanner;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.8.21 下午 15:11
 */
public class mytest {
    public static void main(String[] args) {
        InformationService informationService = new InformationServiceimpl();
        Scanner input = new Scanner(System.in);
        while (true) {
            System.out.println("------------欢迎访问数据库管理系统------------ \n" + "1 - 添加 \n" + "2 - 删除 \n"
                    + "3 - 修改 \n" + "4 - 查看指定信息 \n" + "5 - 查看所有信息 \n" + "6 - 统计数据数据条数 \n"
                    + "7 - 分页查询 \n" + "8 - 退出系统 \n");
            System.out.println("请输入操作");
            switch (input.next()) {
                case "1":
                    System.out.println("请输入id号:");
                    int id = input.nextInt();
                    System.out.println("请输入姓名:");
                    String name = input.next();
                    System.out.println("请输入性别:");
                    String gender = input.next();
                    System.out.println("请输入年龄:");
                    int age = input.nextInt();
                    System.out.println("请输入家庭地址:");
                    String address = input.next();
                    System.out.println("请输入手机号:");
                    String phone = input.next();
                    Information information = new Information(id, name, gender, age, address, phone);
                    int i = informationService.addGet(information);
                    if (i > 0) {
                        System.out.println("添加成功");
                    }
                    break;
                case "2":
                    System.out.println("请输入想要删除的id:");
                    int id1 = input.nextInt();
                    int i1 = informationService.deleteGet(id1);
                    if (i1 > 0) {
                        System.out.println("删除成功");
                    }
                    break;
                case "3":
                    System.out.println("请输入要修改的id号:");
                    int id2 = input.nextInt();
                    int i2 = informationService.updateInformationGet(id2);
                    if (i2 > 0) {
                        System.out.println("修改成功");
                    }
                    break;
                case "4":
                    System.out.println("请输入id号:");
                    int id3 = input.nextInt();
                    Information information1 = informationService.selectfindByidGet(id3);
                    System.out.println(information1);
                    break;
                case "5":
                    System.out.println("以下为所有用户信息:");
                    List<Information> list = informationService.selectFindAllGet();
                    if (list != null) {
                        for (Information information2 : list) {
                            System.out.println(information2);
                        }
                    }
                    break;
                case "6":
                    int i3 = informationService.selectAllCountGet();
                    System.out.println("统计结果为" + i3 + "条数据信息");
                    break;
                case "7":
                    System.out.println("请输入要查看的页数：");
                    int page = input.nextInt();
                    System.out.println("请输入一页显示的条数：");
                    int pageSize = input.nextInt();
                    InformationService informationService1 = new InformationServiceimpl();
                    List<Information> list1 = informationService1.limitGet(page, pageSize);
                    if(list1 != null){
                        for (Information information2 : list1) {
                            System.out.println(information2);
                        }
                    }
                    break;
                case "8":
                    System.exit(0);

            }
        }
    }
}
